package com.ruoyi.zsyh.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhElectricOrder;
import com.ruoyi.zsyh.service.IZsyhElectricOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 整机服务订单Controller
 * 
 * @author yuexl
 * @date 2022-03-11
 */
@Controller
@RequestMapping("/zsyh/electricOrder")
public class ZsyhElectricOrderController extends BaseController
{
    private String prefix = "zsyh/electricOrder";

    @Autowired
    private IZsyhElectricOrderService zsyhElectricOrderService;

    @RequiresPermissions("zsyh:electricOrder:view")
    @GetMapping()
    public String electricOrder()
    {
        return prefix + "/electricOrder";
    }

    @RequiresPermissions("zsyh:electricOrder:view")
    @GetMapping("/electrictOrderUnDeal")
    public String electrictOrderUnDeal()
    {
        return prefix + "/electrictOrderUnDeal";
    }

    @RequiresPermissions("zsyh:electricOrder:view")
    @GetMapping("/addRemark/{id}")
    public String addRemark(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhElectricOrder zsyhElectricOrder = zsyhElectricOrderService.selectZsyhElectricOrderById(id);
        mmap.put("zsyhElectricOrder", zsyhElectricOrder);
        return prefix + "/addRemark";
    }

    @RequiresPermissions("zsyh:electricOrder:view")
    @GetMapping("/endOrder/{id}")
    public String endOrder(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhElectricOrder zsyhElectricOrder = zsyhElectricOrderService.selectZsyhElectricOrderById(id);
        mmap.put("zsyhElectricOrder", zsyhElectricOrder);
        return prefix + "/endOrder";
    }

    /**
     * 查询整机服务订单列表
     */
    @RequiresPermissions("zsyh:electricOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhElectricOrder zsyhElectricOrder)
    {
        startPage();
        List<ZsyhElectricOrder> list = zsyhElectricOrderService.selectZsyhElectricOrderList(zsyhElectricOrder);
        return getDataTable(list);
    }

    /**
     * 导出整机服务订单列表
     */
    @RequiresPermissions("zsyh:electricOrder:export")
    @Log(title = "整机服务订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhElectricOrder zsyhElectricOrder)
    {
        List<ZsyhElectricOrder> list = zsyhElectricOrderService.selectZsyhElectricOrderList(zsyhElectricOrder);
        ExcelUtil<ZsyhElectricOrder> util = new ExcelUtil<ZsyhElectricOrder>(ZsyhElectricOrder.class);
        return util.exportExcel(list, "整机服务订单数据");
    }

    /**
     * 新增整机服务订单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存整机服务订单
     */
    @RequiresPermissions("zsyh:electricOrder:add")
    @Log(title = "整机服务订单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhElectricOrder zsyhElectricOrder)
    {
        return toAjax(zsyhElectricOrderService.insertZsyhElectricOrder(zsyhElectricOrder));
    }

    /**
     * 修改整机服务订单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhElectricOrder zsyhElectricOrder = zsyhElectricOrderService.selectZsyhElectricOrderById(id);
        mmap.put("zsyhElectricOrder", zsyhElectricOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存整机服务订单
     */
    @RequiresPermissions("zsyh:electricOrder:edit")
    @Log(title = "整机服务订单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhElectricOrder zsyhElectricOrder)
    {
        return toAjax(zsyhElectricOrderService.updateZsyhElectricOrder(zsyhElectricOrder));
    }

    /**
     * 取消整机服务订单
     */
    @RequiresPermissions("zsyh:electricOrder:edit")
    @Log(title = "取消整机服务订单", businessType = BusinessType.UPDATE)
    @PostMapping("/cancelElectricOrder")
    @ResponseBody
    public AjaxResult cancelElectricOrder(String id)
    {
        ZsyhElectricOrder zsyhElectricOrder = zsyhElectricOrderService.selectZsyhElectricOrderById(id);
        zsyhElectricOrder.setOrderState("3");
        return toAjax(zsyhElectricOrderService.updateZsyhElectricOrder(zsyhElectricOrder));
    }

    /**
     * 删除整机服务订单
     */
    @RequiresPermissions("zsyh:electricOrder:remove")
    @Log(title = "整机服务订单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhElectricOrderService.deleteZsyhElectricOrderByIds(ids));
    }
}
